<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"  xmlns:ui="http://java.sun.com/jsf/facelets"                        
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"      >
    <h:head>     
        <link href="#{facesContext.externalContext.requestContextPath}/resources/css/default.css" rel="stylesheet" type="text/css" />
        <link href="#{facesContext.externalContext.requestContextPath}/resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
        <link href="#{facesContext.externalContext.requestContextPath}/resources/css/menu.css" rel="stylesheet" type="text/css" />
        <title>Blue Pumpkin Admin p Page</title>
    </h:head>
    <h:body>
        <div class="main_body_admin" >
            <div class="separator_div"/>
            <div class="admin_logo"/>

            <h:form id="frmMain">
                <p:menubar style="text-align: center" >
                    <p:menuitem value="Events" actionListener="#{naviagtionControl.redirectToEventPage()}"  > </p:menuitem> 
                    <p:menuitem value="Prizes" style="color: blueviolet; font-weight: bold" styleClass="admin_menu_current" ></p:menuitem> 
                    <p:menuitem value="Users"   actionListener="#{naviagtionControl.redirectToUserPage()}" ></p:menuitem> 
                    <p:menuitem value="FAQs"  actionListener="#{naviagtionControl.redirectToFAQsPage()}" ></p:menuitem> 
                    <p:menuitem value="Contact" actionListener="#{naviagtionControl.redirectToContactPage()}"  ></p:menuitem> 
                    <p:submenu label="#{userControl.user.fullName}"    >
                        <p:menuitem value="Edit Profile" actionListener="#{userControl.redirectToLogonUserPage()}" ></p:menuitem> 
                        <p:menuitem value="Log out" actionListener="#{userControl.logout()}"  ></p:menuitem> 
                    </p:submenu>

                </p:menubar>
            </h:form>

            <div class="content_display">
                <h:form>
                    <p:toolbar>
                        <p:toolbarGroup>
                            <p:commandButton value="New Prize" actionListener="#{prizeControl.redirectToAddPrize()}"/>
                            <p:commandButton value="View Prizes"  actionListener="#{prizeControl.redirectToListrizes()}" />

                        </p:toolbarGroup>
                    </p:toolbar>
                </h:form>
                <p:spacer height="5px" />
                <h:form>
                    <p:panel id="xxx" header="Prizes with Events">


                        <p:dataTable rendered="true" paginator="true" id="listPrizes" var="event" value="#{prizeControl.allEventsWithPrizes}" emptyMessage="No p found."
                                     rows="5"     
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="5,10,15" >
                            <p:columnGroup type="header">
                                <p:row>
                                    <p:column  headerText="Name"/>
                                    <p:column  headerText="Description"/>
                                    <p:column  headerText="Created Date"/>
                                    <p:column colspan="2" headerText="Actions"/>
                                </p:row>
                            </p:columnGroup>

                            <p:subTable value="#{event.prizeList }" var="p" >

                                <f:facet name="header" class="header_table">
                                    Event: <span style="color: blue; font-weight: bold"> #{event.title}     </span>      
                                    Start : <span style="color: #ff6400"> #{prizeControl.formatDate(event.startDate)}   </span>                                
                                    End : <span style="color: #ff6400">#{prizeControl.formatDate(event.endDate)}   </span>

                                </f:facet>

                                <p:column>
                                    <h:commandLink>
                                        <h:outputText value="#{p.title}" />
                                    </h:commandLink>
                                </p:column>
                                <p:column >

                                    <h:outputText value="#{p.contents}" />

                                </p:column>
                                <p:column >
                                    <h:outputText value="#{p.createdDate}" >
                                        <f:convertDateTime pattern="MM/dd/yyyy" />
                                    </h:outputText>

                                </p:column>
                                <p:column>
                                    <h:commandButton action="#{prizeControl.update(p)}"    value="Update" >   
                                         <f:setPropertyActionListener value="#{p}" target="#{prizeControl.selectedPrize}" />
                                    </h:commandButton>
                                   
                                    <p:commandLink actionListener="#{prizeControl.update(p)}" value="Update"  target="mmm.html">
                                          <f:setPropertyActionListener value="#{p}" target="#{prizeControl.selectedPrize}" />
                                    </p:commandLink>
                                    <p:commandButton  style="width: 90px; font-size: 13px;"  rendered="true" update="@this" process="@this" ajax="false"
                                                      actionListener="#{prizeControl.update(p)}"  value="Update" icon="ui-icon-arrowrefresh-1-w">  
                                         <f:setPropertyActionListener value="#{p}" target="#{prizeControl.selectedPrize}" />

                                    </p:commandButton>
                                </p:column>
                                <p:column>
                                    <p:commandButton  value="Delete" style="width: 90px; font-size: 13px;" onclick="confirmation.show()" icon="ui-icon-close" >
                                        <f:setPropertyActionListener value="#{p}" target="#{prizeControl.selectedPrize}" />
                                    </p:commandButton>
                                    <p:confirmDialog id="confirmDialog" message="Are you sure about delete this Event?"  
                                                     header="Initiating destroy process" severity="alert" widgetVar="confirmation">
                                        <p:commandButton id="confirm" style="font-size: 11px;" actionListener="#{prizeControl.delete(p)}" 
                                                         value="Yes" oncomplete="confirmation.hide()"/>
                                        <p:commandButton id="decline" style="font-size: 11px;" value="No" onclick="confirmation.hide()" />   
                                    </p:confirmDialog>
                                </p:column>

                            </p:subTable>                           

                        </p:dataTable>



                    </p:panel>
                </h:form>
            </div>
        </div>
    </h:body>
</html>
